<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增症状')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-symptom-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">鱼：</label>
            <div class="col-sm-8">
                <select id="cropList" name="cropId" onchange="getDiagnosis()" class="form-control m-b">
                    <option th:each="crop :${cropDictList}" th:value="${crop.cropId}"
                            th:text="${crop.cropName}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">诊断部位：</label>
            <div class="col-sm-8">
                <select id="diagnosisList" name="diaIdP" class="form-control m-b">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">症状：</label>
            <div class="col-sm-8">
                <input name="info" class="form-control" type="text">
            </div>
        </div>

    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "agriculture/symptom"
    $("#form-symptom-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-symptom-add').serialize());
        }
    }
    // 获得诊断列表
    function getDiagnosis() {
        var cropListSelect = document.getElementById("cropList");
        var index = cropListSelect.selectedIndex;
        // selectedIndex代表的是你所选中项的index
        var cropId = cropListSelect.options[index].value;
        $.post("/agriculture/diagnosis/list", {cropIdP: cropId}, function (result) {
            $("#diagnosisList").empty();
            for (var i = 0; i < result.rows.length; i++) {
                var newOption = document.createElement("option");
                newOption.text = result.rows[i].name
                newOption.value = result.rows[i].id
                document.getElementById("diagnosisList").add(newOption);
            }
            if (result.rows.length === 0) {
                var newOption = document.createElement("option");
                newOption.text = "该鱼没有诊断部位信息 请去【诊断部位】页面添加"
                newOption.value = 0
                document.getElementById("diagnosisList").add(newOption);
            }
        });
    }
    // // 获得症状列表
    // function getSymptom() {
    //     var cropListSelect = document.getElementById("diagnosisList");
    //     var index = cropListSelect.selectedIndex;
    //     // selectedIndex代表的是你所选中项的index
    //     var diagnosisId = cropListSelect.options[index].value;
    //     console.log(diagnosisId)
    //     $.post("/agriculture/symptom/list", {diaIdP: diagnosisId}, function (result) {
    //         console.log(result.lows)
    //     });
    // }

    $().ready(function () {
        getDiagnosis()
    })
</script>
</body>
</html>